#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=25,mod=1e9+7;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
int n,a[N],b[N],ans;
map<vector<int>,bool> mp;

int count(int x){
	int res=0;
	while(x) ++res,x-=x&-x;
	return res;
}

signed main(){
	freopen("zha.in","r",stdin);
	freopen("zha.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	for(int i=0;i<(1<<(2*n-2));i++){
		if(count(i)!=n-1) continue;
		int tota=1,totb=1;
		vector<int> c;c.clear();
		for(int j=0;j<2*n-2;j++){
			if(i>>j&1){
				tota++;
				c.push_back(b[totb]);
			}
			else{
				totb++;
				c.push_back(a[tota]);
			}
		}
		if(!mp[c]) mp[c]=1,ans++; 
	}
	cout<<ans%mod;
	return 0;
}